import sys
import os

# 添加包路径
sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))))

from pkg.client.client import Client, Config
from pkg.openapi.openapi import workflow_service, workflow_query_request

def main():
    # 创建客户端配置
    config = Config(
        endpoint="fc-global.ctapi.ctyun.cn",  # 服务端点
        accessKey="Your-AK",                  # 访问密钥
        secretKey="Your-SK",                  # 密钥
        protocol="https",                     # 协议
        method="GET"                          # 方法
    )
    
    # 创建客户端
    client = Client(config)
    
    # 创建工作流服务
    workflow_svc = workflow_service(client)
    
    # 创建工作流查询请求
    request = workflow_query_request(
        page_num=1,                # 页码
        page_size=10,              # 每页大小
        query_prefix="demo"        # 查询前缀
    )
    
    # 查询工作流
    region = "200000002368"        # 区域ID
    response, err = workflow_svc.query_workflow(region, request)
    
    # 处理响应
    if err:
        print(f"Error: {err}")
    else:
        print(f"Status Code: {response.status_code}")
        print(f"Message: {response.message}")
        print(f"Total: {response.return_obj.total}")
        print(f"Page: {response.return_obj.page_num}/{response.return_obj.page_size}")
        print("Workflows:")
        for flow in response.return_obj.flows:
            print(f"  - {flow.name} (ID: {flow.workflow_id})")

if __name__ == "__main__":
    main()

